package com.jdwx.opengl.face.utils;

import java.util.List;

/**
 * @author bai
 * @date 2020/6/19
 * @description
 */
public class StringUtil {
    /**
     * 字符串转整数
     *
     * @param str
     * @param defValue
     * @return
     */
    public static int stringToInt(String str, int defValue) {
        try {
            if(str.indexOf(".")!=-1){
                str = str.substring(0,str.indexOf("."));
            }
            return Integer.parseInt(str);
        } catch (Exception e) {
        }
        return defValue;
    }

    public static long stringToLong(String str, long defValue) {
        try {
            if(str.indexOf(".")!=-1){
                str = str.substring(0,str.indexOf("."));
            }
            return Long.parseLong(str);
        } catch (Exception e) {
        }
        return defValue;
    }

    public static float stringToFloat(String str) {
        float defValue = 0;
        try {
            return Float.parseFloat(str);
        } catch (Exception e) {
        }
        return defValue;
    }

    public static boolean isNullOrEmpty(String str) {
        if (str == null) return true;
        if (str.length() == 0) return true;
        return false;
    }

    public static String join(List<String> arr){
        if(arr==null || arr.size()==0)return "";
        String str=arr.get(0);
        for (int i=1;i<arr.size();i++){
            str=str+','+arr.get(i);
        }
        return str;
    }
}
